#ifndef NETWORKMANAGER_H
#define NETWORKMANAGER_H

#include <WinSock2.h>
#pragma comment( lib, "ws2_32.lib" )

#define MAX_CLIENT_COUNT 256

enum { client_cnct = 0, client_disc, client_command, client_getall, client_getCount };
enum{ server_cntrcv = 0, server_robotpos, server_bulspawns, server_objcount, server_everything };

struct sClient
{
	bool			active;
	unsigned int	lastSequence;
	float			time;

	SOCKADDR_IN		address;

	sClient() 
	{
		active = false;
		time = 0.0f;
	}
};

class NetworkManager
{

private:

	unsigned int m_nClientCount;
	char m_cBuffer[ 1024 ];
	bool m_bFresh;

	SOCKET m_scCom;
	SOCKADDR_IN m_saAddr;

public:

	sClient m_ConnectedClients[ MAX_CLIENT_COUNT ];

	int Init( unsigned short port );
	int Shutdown();

	bool peekBuffer();
	int readBuffer( char* _outBuffer, unsigned int _length );

	void Update( float fDT );

	unsigned int ClientCount() { return m_nClientCount; }
	void SendToAll( char _type, char* buffer, int _length );

	int GetActiveClient();
	int AddActiveClientToList();
	int RemoveClientFromList( unsigned int _ID );
	int SendToActiveClient( char _type, char* buffer, int _length );
	int SetActiveClient( unsigned int ID );


};

#endif